import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:kepu/page/animal_list_page/provider/animal_list_provider.dart';
import 'package:kepu/widgets/custom_grid_view.dart';
import 'package:kepu/widgets/error_widget.dart';
import 'package:kepu/widgets/loading_widget.dart';

class AnimalListPage extends ConsumerWidget {
  const AnimalListPage({super.key});
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var animalList = ref.watch(animalListProviderProvider);
    return Scaffold(
      body: animalList.when(
        data:
            (list) => EasyRefresh(
              onRefresh:()=> ref.refresh(animalListProviderProvider.future),
              onLoad: (){
                ref.read(animalListProviderProvider.notifier).add();
              },
              child: Padding(
                padding: const EdgeInsets.fromLTRB(10, 0, 10, 10),
                child: CustomScrollView(
                  slivers: [customGridView(itemList: list, isPlant: false)],
                ),
              ),
            ),
        error: (e, st) => errorWidget(),
        loading: () => loadWidget(context),
      ),
    );
  }
}
